﻿#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <unordered_map>

using namespace std;
struct TreeNode {
	int val;
	TreeNode *left;
	TreeNode *right;
	TreeNode(int x) : val(x), left(NULL), right(NULL) {}
	
};

class Solution {
public:
	vector<vector<int>> ans;
	void dfs(vector<int>& candidates, int target, int index, int sum, vector<int> samp) {
		if (sum == target) {
			ans.push_back(samp);
			return;
		}
		else if (sum > target || index >= candidates.size()) {
			return;
		}
		dfs(candidates, target, index + 1, sum, samp);
		samp.push_back(candidates[index]);
		dfs(candidates, target, index, sum + candidates[index], samp);
	}
	vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
		vector<int> samp;
		dfs(candidates, target, 0, 0, samp);
		return ans;
	}
};

int main()
{ 
	Solution sol;
	vector<int> test = { 1,2,2,2,3,5 };
	sort(test.begin(), test.end());
	sol.combinationSum(test, 5);
	cout <<endl;
}
